<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://"
			+ request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
	<head>
		<base href="<%=basePath%>">
		<meta http-equiv="content-type"
			content="application/xhtml+xml; charset=utf-8" />
		<title>Uploadify</title>
		<link href="resources/css/uploadify.css" rel="stylesheet" type="text/css" />
		<script type="text/javascript" src="resources/js/jquery-1.3.2.min.js"></script>
		<script type="text/javascript" src="resources/js/swfobject.js"></script>
		<script type="text/javascript"
			src="resources/js/jquery.uploadify.v2.0.3.min.js"></script>
		<script type="text/javascript">
		function uploadifyUpload(){
			var category = $('#category').val();
			if(category=="0"){
				alert("请选择申请类别");
			}else{
				$('#uploadify').uploadifySettings('scriptData', {'category' : category});
   				$('#uploadify').uploadifyUpload();
			}
   					
		}	
		</script>	
		<script type="text/javascript">
        $(document).ready(function() {
            $("#uploadify").uploadify({
                'uploader'       : 'resources/image/uploadify.swf',
                'script'         : 'servlet/fileUpload',
                'cancelImg'      : 'resources/image/cancel.png',
                'queueID'        : 'fileQueue',
                'auto'           : false,
                'multi'          : false,
                'buttonText'     : 'Browse file',
                            
	            onComplete: function (evt, queueID, fileObj, response, data) {
					$('<li></li>').appendTo('.files').text(response);
				},
				onError: function(a, b, c, d) {
		             alert("文件上传失败");
       			}
            });

        });
        $(function(){
        	$("#compolete").click(function(){
        		var reg = /%20/g;
        		var pairs = [];
        		$(".files li").each(function(){
        			var node = $(this).text() + ""
        			var path = node.replace(/\：/g,"/").replace(/\s*COMPOLETE\s*/gi,"");
        			var name = node.substring(0,node.indexOf("："));
        			var pair = encodeURIComponent(name).replace(reg,"+") + "=" +path;
        			pairs.push(pair);
        		})
        		var value = pairs.join("&");
        		$.ajax({
        			method: "post",
        			url: "pages/students/student_add.jsp",
        			data: value,
        			success :function(data){
        				
        			}
        		})
        	})
        })
        </script>
	</head>
	<body>
	<div class="mainContainer">
	<div class="mainInfo">
	<br/>
		<p>
			操作流程说明：<br/>
			1.选择类别<br/>
			2.点击"Browse file"按钮添加附件<br/>
			3.一次性可以选择多个附件<br/>
			4.点击"开始上传"，或"取消所有上传"<br/>
		</p>
		类别：
		<select name="category" id="category">
			<option value="0">
				------请选择类别------
			</option>

			<option value="Application">外国留学人员来华签证申请表</option>
			<option value="Admission">录取通知书</option>
			<option value="Passport">护照</option>
			<option value="ChineseVisa">中华人民共和国签证</option>

		</select>
		<br/><br/><br/>
		添加附件：
		<input type="file" name="uploadify" id="uploadify" />		
		
		<div id="fileQueue"></div>
		<br/><br/><br/>
		<p>
			<a href="javascript:;" onClick="javascript:uploadifyUpload()">开始上传</a>&nbsp;
			<a href="javascript:jQuery('#uploadify').uploadifyClearQueue()">取消所有上传</a>
			<a href="javascript:void(0);" id='compolete'>完成</a>
		</p>
		<p>
			
		</p>
		<ol class="files"></ol>
		</div>
</div>
	</body>
</html>